<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:y="clr-namespace:ExoImplantEditor.Controls;assembly=ExoImplantEditor"
    xmlns:z="clr-namespace:ExoImplantEditor;assembly=ExoImplantEditor"
    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
    xmlns:DentalConfig="clr-namespace:DentalConfig;assembly=DentalConfig"
    xmlns:DentalGUIHelper="clr-namespace:DentalGUIHelper;assembly=DentalConfig">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Common/commons.xaml"/>
		<ResourceDictionary Source="DentalCAD/NamedStyles/MaterialDesignTheme.GroupSelectorStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!-- Custom background color used in editor -->
    <SolidColorBrush x:Key="EditorBackgroundBrush" Color="{StaticResource MaterialDesignColorToolBarBackground}"/>
    
    <!-- In ExoImplantEditor we want to be able to distinguish readonly textboxes from those which allow input -->
    <SolidColorBrush x:Key="ExoImplantEditorTextEditBaseBackgroundReadOnly" Color="Transparent"/>
    <SolidColorBrush x:Key="ExoImplantEditorTextEditBaseBackground" Color="{StaticResource MaterialDesignColorCardBackground}"/>
    <SolidColorBrush x:Key="ExoImplantEditorTextErrorBackground" Color="#FF8080"/>
    <SolidColorBrush x:Key="ExoImplantEditorTextEditIsParentValueBrush" Color="{StaticResource MaterialDesignColorBody}" Opacity="0.3" />

    <!-- All textboxes should use our specific background color and support IsParentValue attached property and IsReadOnly -->
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
        <Setter Property="Background" Value="{DynamicResource ExoImplantEditorTextEditBaseBackground}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=(z:IsParentValueBehavior.IsParentValue), RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="{StaticResource ExoImplantEditorTextEditBaseBackgroundReadOnly}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- All comboboxes should use same background as textboxes. Also support IsParentValue attached property and IsReadOnly -->
    <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
        <Setter Property="Background" Value="{DynamicResource ExoImplantEditorTextEditBaseBackground}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=(z:IsParentValueBehavior.IsParentValue), RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="{StaticResource ExoImplantEditorTextEditBaseBackgroundReadOnly}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    
    <!-- We have some custom controls in ExoImplantEditor. Make sure those are styled based properly -->
    <Style TargetType="y:exoTextBox" BasedOn="{StaticResource {x:Type TextBox}}" >
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsParentValue, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="{StaticResource ExoImplantEditorTextEditBaseBackgroundReadOnly}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="y:exoCheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsParentValue, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="y:exoDoubleTextBox" BasedOn="{StaticResource {x:Type TextBox}}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsParentValue, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="{StaticResource ExoImplantEditorTextEditBaseBackgroundReadOnly}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="y:exoListBox" BasedOn="{StaticResource {x:Type ListBox}}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsParentValue, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <Style TargetType="y:exoIntTextBox" BasedOn="{StaticResource {x:Type TextBox}}" >
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsParentValue, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Foreground" Value="{StaticResource ExoImplantEditorTextEditIsParentValueBrush}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Background" Value="{StaticResource ExoImplantEditorTextEditBaseBackgroundReadOnly}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!-- Some ExoImplantEditor buttons need to suport custom solid background coloring (e.g. in ColorParamControl). The only material design button which allows non transparent background is MaterialDesignRaisedButton -->
    <Style x:Key="ButtonWithSolidBackground" TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
		<Setter Property="BorderBrush" Value="{DynamicResource MidContrastPrimaryBrush}"/>
		<Setter Property="Background" Value="{DynamicResource ButtonBrush}"/>
	</Style>

    <!-- Style ToggleButtons like normal buttons by default -->
    <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignOutlinedContentToggleButton}" />

    <!-- Be aware: the style defined in MaterialDesignTheme.Window.xaml does not propagate to derived classes. Thus we need to explicitly apply it to all our Window based classes -->
    <Style x:Key="ExoImplantEditorWindowBaseStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}">
        <!-- in addition to the colors defined in MaterialDesignTheme.Window.xaml, we also want to use the material fonts -->
        <Setter Property="TextElement.Foreground" Value="{DynamicResource MaterialDesignBody}" />
        <Setter Property="TextElement.FontFamily" Value="{DynamicResource DefaultFont}" />
    </Style>
    <Style TargetType="{x:Type z:MainWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:SettingsWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:ValidationTools}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:Tools}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:ConnectionIDsEditWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:PartInfoEditWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:PartInfoGenerator}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:ViewerButtonsWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type y:SetScrewChannelByAngleDialog}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type z:ExoErrorsBox}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type DentalConfig:AboutWindow}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" />
    <Style TargetType="{x:Type Window}" BasedOn="{StaticResource ExoImplantEditorWindowBaseStyle}" /><!-- Also propagate our base window style to all none derived windows -->

    <BooleanToVisibilityConverter x:Key="boolToVisConv" />

    <!-- Expander variant which does not use a StackPanel. Using a StackPanel will break controls which try to fill all the available space. Note that due to not using a StackPanel, this does not support transition animations -->
    <Style x:Key="MaterialDesignRaisedCardExpanderWithoutStackPanel" BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type Expander}">
              <wpf:Card Name="maskCard" Style="{DynamicResource MaterialDesignRaisedCard}" wpf:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch" Background="{TemplateBinding Background}" UniformCornerRadius="4">
                <DockPanel Margin="{TemplateBinding Padding}">
                  <ToggleButton
                    Name="HeaderSite"
                    Focusable="False"
                    IsTabStop="False"
                    DockPanel.Dock="Top"
                    BorderThickness="0"
                    Cursor="Hand"
                    IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                    Margin="2,0"
                    Style="{StaticResource MaterialDesignSlimFlatExpanderDownHeaderStyle}"
                    Foreground="{TemplateBinding Foreground}"
                    TextBlock.FontFamily="{DynamicResource HeaderFontFamily}"
                    TextBlock.FontSize="14"
                    Content="{TemplateBinding Header}"
                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                    ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                    ContentStringFormat="{TemplateBinding HeaderStringFormat}"/>
                  <Border Name="ContentSite" DockPanel.Dock="Bottom">
                    <ContentPresenter
                      Name="PART_Content"
                      Visibility="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource boolToVisConv}}"
                      Focusable="False"
                      ContentTemplate="{TemplateBinding ContentTemplate}"
                      ContentStringFormat="{TemplateBinding ContentStringFormat}"
                      ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
                  </Border>
                </DockPanel>
              </wpf:Card>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
    </Style>

    <!-- for our visibility checkboxes, we need some additional spacing to the left to not overlap with a potential viewer ruler -->
    <Style x:Key="ExoImplantEditorGroupSelectorMargin" TargetType="{x:Type FrameworkElement}">
        <Setter Property="Margin" Value="44,16,44,16" />
    </Style>

    <Style x:Key="GridItemsStyle" TargetType="ItemsControl">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="35"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="A"></ColumnDefinition>
                            <ColumnDefinition ></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="30" SharedSizeGroup="D"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="42" SharedSizeGroup="B"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="38" SharedSizeGroup="C"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CompatibilityItemsStyle"  TargetType="ItemsControl">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="A"></ColumnDefinition>
                            <ColumnDefinition ></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="30" SharedSizeGroup="D"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" MinWidth="42" SharedSizeGroup="B"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"  MinWidth="38" SharedSizeGroup="C"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="DentalGUIHelper:VirtualizingComboBox" BasedOn="{StaticResource {x:Type ComboBox}}" />

    <Style TargetType="DentalGUIHelper:FilterableComboBox" BasedOn="{StaticResource {x:Type DentalGUIHelper:VirtualizingComboBox}}">
        <Setter Property="StaysOpenOnEdit" Value="True" />
        <Setter Property="IsEditable" Value="True" />
        <Setter Property="IsTextSearchEnabled" Value="False" />

        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock DataContext="{Binding}" Text="{Binding}" DentalGUIHelper:FilterableComboBox.FilteredInlines="{Binding MyFilter, RelativeSource={RelativeSource FindAncestor, AncestorType=DentalGUIHelper:FilterableComboBox}}"  />
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
